package com.xiao.xin.core.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private static final String REQUEST_OK = "登录成功";
    private String msg;
    private T data;
    private int code;

    public static <T> Result<T> success() {
        return Result.
                <T>builder()
                .code(200)
                .msg(REQUEST_OK)
                .build();
    }

    public static <T> Result<T> success(T data) {
        return Result.
                <T>builder()
                .data(data)
                .code(200)
                .msg(REQUEST_OK)
                .build();
    }

    public static <T> Result<T> error(int code,String msg) {
        return Result.
                <T>builder()
                .code(code)
                .msg(msg)
                .build();
    }

    public static <T> Result<T> error(String msg) {
        return Result.
                <T>builder()
                .code(401)
                .msg(msg)
                .build();
    }
}
